﻿using log4net;
using log4net.Config;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ZHDJ.Core.Log
{

    public  class Log4netHelper
    {
        //log4net日志专用
        public static readonly log4net.ILog logInfo = log4net.LogManager.GetLogger("loginfo");
        public static readonly log4net.ILog logError = log4net.LogManager.GetLogger("logerror");

        public static void SetConfig()
        {
            log4net.Config.XmlConfigurator.Configure();
        }

        public static void SetConfig(FileInfo configFile)
        {
            log4net.Config.XmlConfigurator.Configure(configFile);
        }
        /// <summary>
        /// 普通的文件记录日志
        /// </summary>
        /// <param name="info"></param>
        public static void WriteLog(string info)
        {
            if (logInfo.IsInfoEnabled)
            {
                logInfo.Info(info);
            }
        }
        /// <summary>
        /// 错误日志
        /// </summary>
        /// <param name="info"></param>
        /// <param name="se"></param>
        public static void WriteLog(string info, Exception se)
        {

            if (logError.IsErrorEnabled)
            {
                logError.Error(info + "\r\n" + se.Message + "\r\n" + se.StackTrace + "\r\n" + se.InnerException);
            }

        }

        /// <summary>
        /// 错误日志
        /// </summary>
        /// <param name="info"></param>
        /// <param name="se"></param>
        public static void WriteLog( Exception se)
        {
            if (logError.IsErrorEnabled)
            {
                logError.Error(se.Message+"\r\n"+se.StackTrace + "\r\n"+se.InnerException);
            }
        }
    }
    
}

